package com.example.compose.utils

import android.util.Log
import com.example.compose.BuildConfig

object LogUtil {

    private var className: String? = null
    private var methodName: String? = null
    private var lineName = 0

    fun v(message: String) {
        if (BuildConfig.DEBUG) {
            createLogName(Throwable().stackTrace)
            Log.v(
                "$className$methodName$lineName",
                message
            )
        }
    }

    fun d(message: String) {
        if (BuildConfig.DEBUG) {
            createLogName(Throwable().stackTrace)
            Log.d(
                "$className$methodName$lineName",
                message
            )
        }
    }

    fun i(message: String) {
        if (BuildConfig.DEBUG) {
            createLogName(Throwable().stackTrace)
            Log.i(
                "$className$methodName$lineName",
                message
            )
        }
    }

    fun e(message: String) {
        if (BuildConfig.DEBUG) {
            createLogName(Throwable().stackTrace)
            Log.e(
                "$className$methodName$lineName",
                message
            )
        }
    }

    private fun createLogName(stackTrace: Array<StackTraceElement>) {
        className = "LogUtil "+stackTrace[1].className
        methodName = stackTrace[1].methodName
        lineName = stackTrace[1].lineNumber
    }
}
